﻿using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Text;

namespace AnnieSharp
{
    public static class AnnieExtension
    {
        /// <summary>
        /// 将Annie的矩阵转化为skia的矩阵
        /// </summary>
        /// <param name="matrix"></param>
        /// <returns></returns>
        public static SKMatrix ToSkMatrix(this Matrix matrix)
        {
            var skMatrix = SKMatrix.MakeIdentity();

            //skMatrix.GetValues(new float[] { matrix.A, matrix.B, matrix.Tx, matrix.C, matrix.D, matrix.Ty, 0, 0, 1 });
            skMatrix.ScaleX = matrix.A;
            skMatrix.ScaleY = matrix.D;
            skMatrix.SkewX = matrix.B;
            skMatrix.SkewY = matrix.C;
            skMatrix.TransX = matrix.Tx;
            skMatrix.TransY = matrix.Ty;

            return skMatrix;
        }

        /// <summary>
        /// 将Skia的矩阵转化为Annie的矩阵
        /// </summary>
        /// <param name="skMatrix"></param>
        /// <returns></returns>
        public static Matrix ToAnnieMatrix(this SKMatrix skMatrix)
        {

            //skMatrix.Values = new float[] { matrix.A, matrix.B, matrix.Tx, matrix.C, matrix.D, matrix.Ty, 0, 0, 1 };
            var skValues = skMatrix.Values;

            return new Matrix(skValues[0], skValues[1], skValues[3], skValues[4], skValues[2], skValues[5]);
        }

        /// <summary>
        /// 讲AnnieRect转化为SkRect
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        public static SKRect ToSkRect(this Rectangle rect)
        {
            var skReck = SKRect.Create(rect.X,rect.Y,rect.Width,rect.Height);
            return skReck;
        }

    }
}
